﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace Common
{
    public static class SessionExtender
    {
        public static void RemoveUserDBPrefix(this HttpSessionState session)
        {
            if (HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity != null &&
                !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
            {
                session.Remove(HttpContext.Current.User.Identity.Name);
            }
        }

        public static string GetUserDBPrefix(this HttpSessionState session)
        {
            if (HttpContext.Current == null || HttpContext.Current.User == null || HttpContext.Current.User.Identity == null ||
                string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
            {
                return string.Empty;
            }
            if (session[HttpContext.Current.User.Identity.Name] == null)
            {
                return string.Empty;
            }
            return session[HttpContext.Current.User.Identity.Name] as string;
        }

        public static void SetUserDBPrefix(this HttpSessionState session, string userName, string dbpre)
        {
            session[userName] = dbpre;
        }
    }
}
